/**
 * @param {string} s
 * @param {number} k
 * @return {string}
*/
var reverseStr = function(s, k) {
  let result = "";
  for(let i = 0; i < Math.ceil(s.length / k); i++) {
    if(i % 2 == 0) {
      result += s.slice(i * k, (i + 1) * k).split("").reverse().join("");
    } else {
      result += s.slice(i * k, (i + 1) * k).split("").join("");
    }
  }
  return result;
};
let s = "abcdefg", k = 2;
console.log(reverseStr(s, k));
s = "abcd", k = 2;
console.log(reverseStr(s, k));
